from sqlmodel import Session

from dependencies import SessionDep
from models import User, UserCreate


class UserService:
    @classmethod
    def as_dependency(cls, db: Session = SessionDep):
        return cls(db)

    def __init__(self, db: Session = SessionDep):
        self.db = db

    def create_user(self, user_create: UserCreate) -> User:
        db_hero = User.model_validate(user_create)
        self.db.add(db_hero)
        self.db.commit()
        self.db.refresh(db_hero)
        return db_hero
